<template>
  <drag-dialog v-model="visible" title="样式设置">
    <el-form label-position="right" label-width="100" label-suffix=":">
      <el-form-item label="样式预览">
        <span :style="{ fontSize: localData.fontSize, fontWeight: localData.fontWeight, color: localData.color }">文本</span>
      </el-form-item>
      <el-form-item label="字体大小">
        <el-input-number v-model="localData.fontSize" controls-position="right" />
      </el-form-item>
      <el-form-item label="字体粗细">
        <el-input-number v-model="localData.fontWeight" controls-position="right" />
      </el-form-item>
      <el-form-item label="字体颜色">
        <el-color-picker v-model="localData.color" />
      </el-form-item>
    </el-form>
    <template #footer>
      <dialog-footer @ok="submit" @cancel="cancel" />
    </template>
  </drag-dialog>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { cloneDeep } from 'lodash-es';

export default defineComponent({
  name: 'TitleSetting',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      localData: {},
      visible: false
    };
  },
  watch: {
    modelValue: {
      handler(newVal) {
        this.visible = newVal;
      },
      immediate: true
    },
    visible(newVal) {
      this.$emit('update:modelValue', newVal);
    },
    data: {
      handler(newVal) {
        this.localData = cloneDeep(newVal);
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    submit() {
      this.$emit('submit', this.localData);
      this.visible = false;
    },
    cancel() {
      this.visible = false;
    }
  }
});
</script>
